#include <stdlib.h>
#include <gl/glut.h>
#include <gl/glui.h>
#include <gl/gl.h>
#include <iostream>
#include <fstream>





using namespace std;




GLfloat light_ambient0 []  = { 0.0, 0.0, 0.0, 1.0 }; 
GLfloat light_diffuse0 []  = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat light_specular0 [] = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat light_position0 [] = { 1.0, 10.0, 1.0, 0.0 }; 

GLfloat light_ambient1 []  = { 0.0, 0.0, 0.0, 1.0 }; 
GLfloat light_diffuse1 []  = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat light_specular1 [] = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat light_position1 [] = { 1.0, 10.0, 1.0, 0.0 }; 

GLfloat light_ambient2 []  = { 0.0, 0.0, 0.0, 1.0 }; 
GLfloat light_diffuse2 []  = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat light_specular2 [] = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat light_position2 [] = { 1.0, 10.0, 1.0, 0.0 }; 

GLfloat light_ambient3 []  = { 0.0, 0.0, 0.0, 1.0 }; 
GLfloat light_diffuse3 []  = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat light_specular3 [] = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat light_position3 [] = { 1.0, 10.0, 1.0, 0.0 }; 

GLfloat light_ambient4 []  = { 0.0, 0.0, 0.0, 1.0 }; 
GLfloat light_diffuse4 []  = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat light_specular4 [] = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat light_position4 [] = { 1.0, 10.0, 1.0, 0.0 }; 

GLfloat light_ambient5 []  = { 0.0, 0.0, 0.0, 1.0 }; 
GLfloat light_diffuse5 []  = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat light_specular5 [] = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat light_position5 [] = { 1.0, 10.0, 1.0, 0.0 }; 

GLfloat light_ambient6 []  = { 0.0, 0.0, 0.0, 1.0 }; 
GLfloat light_diffuse6 []  = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat light_specular6 [] = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat light_position6 [] = { 1.0, 10.0, 1.0, 0.0 }; 

GLfloat light_ambient7 []  = { 0.0, 0.0, 0.0, 1.0 }; 
GLfloat light_diffuse7 []  = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat light_specular7 [] = { 1.0, 1.0, 1.0, 1.0 }; 
GLfloat light_position7 [] = { 1.0, 10.0, 1.0, 0.0 }; 


GLfloat mat_diffuse_copa []   = { 1.0, 0, 0, 1.0 }; 
GLfloat mat_specular_copa []  = { 0, 1, 0.5, 1.0 }; 
GLfloat mat_emission_copa []   = { 0.1, 0, 0, 1.0 }; 
GLfloat mat_ambient_copa []   = { 1.0, 0, 0, 1.0 }; 
GLfloat mat_shininess_copa [] = { 70 };

GLfloat mat_diffuse_bot []   = { 1.0, 0, 0.3, 1.0 }; 
GLfloat mat_specular_bot []  = { 1, 1, 0.5, 1.0 }; 
GLfloat mat_emission_bot []   = { 0.8, 0, 0, 1.0 }; 
GLfloat mat_ambient_bot []   = { 1.0, 0, 0, 1.0 }; 
GLfloat mat_shininess_bot [] = { 60 };

GLfloat mat_diffuse_copa2 []   = { 1.0, 0, 0.5, 1.0 }; 
GLfloat mat_specular_copa2 []  = { 0.7, 0.11, 0.5, 1.0 }; 
GLfloat mat_emission_copa2 []   = { 0.1, 1, 0, 1.0 }; 
GLfloat mat_ambient_copa2 []   = { 1.0, 0, 1, 1.0 }; 
GLfloat mat_shininess_copa2 [] = { 70 };

GLfloat mat_diffuse_cake []   = { 1.0, 0, 0.5, 1.0 }; 
GLfloat mat_specular_cake []  = { 0.4, 0.11, 1, 1.0 }; 
GLfloat mat_emission_cake []   = { 0.2,0, 0.7, 1.0 }; 
GLfloat mat_ambient_cake []   = {1.0, 0, 0, 1.0 }; 
GLfloat mat_shininess_cake [] = { 25 };

GLfloat mat_diffuse []   = { 0.3, 0.6, 0, 1.0 }; 
GLfloat mat_specular []  = { 0, 1, 0.5, 1.0 }; 
GLfloat mat_emission []   = { 0, 0.1, 0, 1.0 }; 
GLfloat mat_ambient []   = { 0.7, 0, 0.1, 1.0 }; 
GLfloat mat_shininess [] = { 50 };

//gui & gui2

float obj_trans[] = { 0.0, 0.0, 0.0 };
float sca_x,sca_y,sca_z=0.0;
GLUI *glui;
GLUI *glui2;
GLUI_RadioGroup *radio;
bool smooth=true;
GLUI_Listbox* listLight;
GLUI_Listbox* listLightOnOff;

int selLight=0;
int lighton=0;
bool L0,L1,L2,L3,L4,L5,L6,L7=false;
bool lights[8]={true,false,false,false,false,false,false,false};





GLUI_Panel      *obj_panel;
GLUI_Panel      *obj_cake;
GLUI_Panel      *obj_glass1;
GLUI_Panel      *obj_glass2;
GLUI_Panel      *obj_bottle;

int segments;


//GLUquadricObj *quadratic;
//quadratic=gluNewQuadric();

float mouse_x, mouse_y;
float rotation_x=0.0;
float rotation_y=0.0;
float profundidad=0.0;

bool BotonIzquierda=false;
bool BotonDerecha=false;

int   WindowSizeH = 450;
int   WindowSizeW = 300;

int TamRealVentanaH=450;
int TamRealVentanaW=480;





//declaraciones generales

//subventanas defincion y funciones


int ventCentral;
void CentralDisplay();
void CentralReshape(int w, int h);

int ventPrincipal;
void PrincipalReshape(int w, int h);
void PrincipalDisplay();


void ModoTrabajo();
void drawString(char* s);
static char label[100];


void setCamera(float posX, float posY, float posZ, float targetX, float targetY, float targetZ);



void cleanInfo()
{
	sca_x=1;
	sca_y=1;
	sca_z=1;

	obj_trans[0] = 0;
	obj_trans[1] = 0;
	obj_trans[2] = 0;

	
	
}



void myGlutMotion(int x, int y )
{
	if(BotonIzquierda)
	{rotation_x +=  (y - mouse_y);
	rotation_y +=  (x - mouse_x);}
	else if(BotonDerecha)
	{
		profundidad+=(y-mouse_y);
	}

	mouse_x = x;
	mouse_y = y;

	glutPostRedisplay(); 
}
void click(int button, int state, int x, int y)
{

if ( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) {
		mouse_x = x;
		mouse_y = y;
		BotonIzquierda=true;
		BotonDerecha=false;
	}
else if( button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN ) {
		mouse_y = y;
		BotonIzquierda=false;
		BotonDerecha=true;
		
	}

}




void keyboard (unsigned char tecla, int x, int y)
{
	switch (tecla)
	{
	case 27: // Escape
		
		break;
	}
}


int init (void) 
{

	glClearColor (0.0, 0.0, 0.0, 0.0);
	
	glutMouseFunc (click);
	glutMotionFunc( myGlutMotion );
	glutKeyboardFunc(keyboard);

	cleanInfo();

	return 0;
}

void ModoTrabajo()
{
	
	glutSetWindow(ventCentral);
	if(smooth==false)glShadeModel(GL_FLAT);
	else glShadeModel(GL_SMOOTH);
	glutPostRedisplay();


}

void control_cb( int control )
{


	switch(control){

		case 1:
			if (radio->get_int_val() ==0)
				smooth=false;
			else
				smooth=true;

			break;

		case 2:
			obj_trans[0]=light_position0[0];
			obj_trans[1]=light_position0[1];
			obj_trans[2]=light_position0[2];

			switch(selLight)
			{
			case 0:
				obj_trans[0]=light_position0[0];
				obj_trans[1]=light_position0[1];
				obj_trans[2]=light_position0[2];
				
				break;
			case 1:
				obj_trans[0]=light_position1[0];
				obj_trans[1]=light_position1[1];
				obj_trans[2]=light_position1[2];
				break;
			case 2:
				obj_trans[0]=light_position2[0];
				obj_trans[1]=light_position2[1];
				obj_trans[2]=light_position2[2];
				break;
			case 3:
				obj_trans[0]=light_position3[0];
				obj_trans[1]=light_position3[1];
				obj_trans[2]=light_position3[2];
				break;
			case 4:
				obj_trans[0]=light_position4[0];
				obj_trans[1]=light_position4[1];
				obj_trans[2]=light_position4[2];
				break;
			case 5:
				obj_trans[0]=light_position5[0];
				obj_trans[1]=light_position5[1];
				obj_trans[2]=light_position5[2];
				break;
			case 6:
				obj_trans[0]=light_position6[0];
				obj_trans[1]=light_position6[1];
				obj_trans[2]=light_position6[2];
				break;
			case 7:
				obj_trans[0]=light_position7[0];
				obj_trans[1]=light_position7[1];
				obj_trans[2]=light_position7[2];
				break;
			
			default:
				break;
			}
			
			break;

		case 3:
			if(lighton==0)
			{
				switch(selLight)
				{
				case 0:
					glDisable(GL_LIGHT0);
					break;
				case 1:
					glDisable(GL_LIGHT1);	
					break;
				case 2:
					glDisable(GL_LIGHT2);
					break;
				case 3:
					glDisable(GL_LIGHT3);
					break;
				case 4:
					glDisable(GL_LIGHT4);
					break;
				case 5:
					glDisable(GL_LIGHT5);
					break;
				case 6:
					glDisable(GL_LIGHT6);
					break;
				case 7:
					glDisable(GL_LIGHT7);
					break;
				
				default:
					break;
				}
			}
			else
			{
			switch(selLight)
				{
				case 0:
					glEnable(GL_LIGHT0);
					break;
				case 1:
					glEnable(GL_LIGHT1);	
					break;
				case 2:
					glEnable(GL_LIGHT2);
					break;
				case 3:
					glEnable(GL_LIGHT3);
					break;
				case 4:
					glEnable(GL_LIGHT4);
					break;
				case 5:
					glEnable(GL_LIGHT5);
					break;
				case 6:
					glEnable(GL_LIGHT6);
					break;
				case 7:
					glEnable(GL_LIGHT7);
					break;
				
				default:
					break;
				}
			}

		
			break;

		case 4:
			switch(selLight)
			{
			case 0:
				light_position0[0]=obj_trans[0];
				break;
			case 1:
				light_position1[0]=obj_trans[0];
				break;
			case 2:
				light_position2[0]=obj_trans[0];
				break;
			case 3:
				light_position3[0]=obj_trans[0];
				break;
			case 4:
				light_position4[0]=obj_trans[0];
				break;
			case 5:
				light_position5[0]=obj_trans[0];
				break;
			case 6:
				light_position6[0]=obj_trans[0];
				break;
			case 7:
				light_position7[0]=obj_trans[0];
				break;
			
			default:
				break;
			}

		
			break;

		case 5:
			switch(selLight)
			{
			case 0:
				light_position0[1]=obj_trans[1];
				break;
			case 1:
				light_position1[1]=obj_trans[1];
				break;
			case 2:
				light_position2[1]=obj_trans[1];
				break;
			case 3:
				light_position3[1]=obj_trans[1];
				break;
			case 4:
				light_position4[1]=obj_trans[1];
				break;
			case 5:
				light_position5[1]=obj_trans[1];
				break;
			case 6:
				light_position6[1]=obj_trans[1];
				break;
			case 7:
				light_position7[1]=obj_trans[1];
				break;
			
			default:
				break;
			}
			
			break;

		case 6:
			switch(selLight)
			{
			case 0:
				light_position0[2]=obj_trans[2];
				break;
			case 1:
				light_position1[2]=obj_trans[2];
				break;
			case 2:
				light_position2[2]=obj_trans[2];
				break;
			case 3:
				light_position3[2]=obj_trans[2];
				break;
			case 4:
				light_position4[2]=obj_trans[2];
				break;
			case 5:
				light_position5[2]=obj_trans[2];
				break;
			case 6:
				light_position6[2]=obj_trans[2];
				break;
			case 7:
				light_position7[2]=obj_trans[2];
				break;
			
			default:
				break;}

			break;
		
	}

	ModoTrabajo();


}

void myGlutIdle( void )
{
	/* According to the GLUT specification, the current window is 
	undefined during an idle callback.  So we need to explicitly change
	it if necessary */
	if ( glutGetWindow() != ventCentral ) 
		glutSetWindow(ventCentral);  

	/*  GLUI_Master.sync_live_all();  -- not needed - nothing to sync in this
	application  */
	if(GL_LIGHT0)glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
	if(GL_LIGHT1)glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
	if(GL_LIGHT2)glLightfv(GL_LIGHT2, GL_POSITION, light_position2);
	if(GL_LIGHT3)glLightfv(GL_LIGHT3, GL_POSITION, light_position3);
	if(GL_LIGHT4)glLightfv(GL_LIGHT4, GL_POSITION, light_position4);
	if(GL_LIGHT5)glLightfv(GL_LIGHT5, GL_POSITION, light_position5);
	if(GL_LIGHT6)glLightfv(GL_LIGHT6, GL_POSITION, light_position6);
	if(GL_LIGHT7)glLightfv(GL_LIGHT7, GL_POSITION, light_position7);


	glutPostRedisplay();

}


int main(int argc, char** argv)
{

	// Initialize GLUT
	glutInit(&argc, argv);

	// Request a double buffer
	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

	 
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 


	// Window size (width, height)
	//glutInitWindowSize (WindowSizeW, WindowSizeH); 

	// Initial position (x, y) 
	glutInitWindowPosition (50, 50);

	//Real Size of the window
	glutInitWindowSize(TamRealVentanaW,TamRealVentanaH);


	
	setCamera(0, 0, 550, 0, 0, 0);

	// Set the display callback
	//glutDisplayFunc(display); 
	

	ventPrincipal=glutCreateWindow("Assignment1 - IGU");
	glutDisplayFunc(PrincipalDisplay);
	glutReshapeFunc(PrincipalReshape);



	ventCentral=glutCreateSubWindow(ventPrincipal,0,0,WindowSizeW,WindowSizeH);
	glutDisplayFunc(CentralDisplay);
	glutReshapeFunc(CentralReshape);


		
	GLfloat lmodel_ambient [] = { 0.7, 0.7, 0.7, 1.0 }; 
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); 

   //glLightfv(GL_LIGHT0, GL_POSITION, light_position0); 
 

	glEnable(GL_LIGHTING);
	glEnable(GL_DEPTH_TEST);



	// Initialize the application and OpenGL
	init ();

	
	
	//GLUI


	
	glui = GLUI_Master.create_glui( "Light",0,600,50 );
	listLight = new GLUI_Listbox (glui,"Lights:",&selLight,2,control_cb);
	listLight->add_item(0,"Light 0");
	listLight->add_item(1,"Light 1");
	listLight->add_item(2,"Light 2");
	listLight->add_item(3,"Light 3");
	listLight->add_item(4,"Light 4");
	listLight->add_item(5,"Light 5");
	listLight->add_item(6,"Light 6");
	listLight->add_item(7,"Light 7");

	listLightOnOff= new GLUI_Listbox (glui,"Off?:",&lighton,3,control_cb);
	listLightOnOff->add_item(0,"Off");
	listLightOnOff->add_item(1,"On");
	
	new GLUI_Translation(glui,"Translate X",GLUI_TRANSLATION_X,&obj_trans[0],4,control_cb);
	new GLUI_Translation(glui,"Translate Y",GLUI_TRANSLATION_Y,&obj_trans[1],5,control_cb);
	new GLUI_Translation(glui,"Translate Z",GLUI_TRANSLATION_Z,&obj_trans[2],6,control_cb);


	GLUI_Master.set_glutIdleFunc( myGlutIdle );

	int var;
	glui2 = GLUI_Master.create_glui_subwindow( ventPrincipal,GLUI_SUBWINDOW_RIGHT );
	radio = new GLUI_RadioGroup( glui2,&var,1,control_cb );
	new GLUI_RadioButton( radio, "Constant Shading " );
	new GLUI_RadioButton( radio, "Smooth Shading " );

	////////////////////////table
	obj_panel = new GLUI_Rollout(glui2, "Table", false );
	GLUI_Spinner *spinner =  new GLUI_Spinner( obj_panel, "Ambient R:", &mat_ambient[0]);
	GLUI_Spinner *spinner2 =  new GLUI_Spinner( obj_panel, "Ambient G:", &mat_ambient[1]);
	GLUI_Spinner *spinner3 =  new GLUI_Spinner( obj_panel, "Ambient B:", &mat_ambient[2]);
	spinner->set_int_limits( 0, 1 );
	spinner->set_alignment( GLUI_ALIGN_RIGHT );
	spinner2->set_int_limits( 0, 1 );
	spinner2->set_alignment( GLUI_ALIGN_RIGHT );
	spinner3->set_int_limits( 0, 1 );
	spinner3->set_alignment( GLUI_ALIGN_RIGHT );

	GLUI_Spinner *spinner4 =  new GLUI_Spinner( obj_panel, "Diffuse R:", &mat_diffuse[0]);
	GLUI_Spinner *spinner5 =  new GLUI_Spinner( obj_panel, "Diffuse G:", &mat_diffuse[1]);
	GLUI_Spinner *spinner6 =  new GLUI_Spinner( obj_panel, "Diffuse B:", &mat_diffuse[2]);
	spinner4->set_int_limits( 0, 1 );
	spinner4->set_alignment( GLUI_ALIGN_RIGHT );
	spinner5->set_int_limits( 0, 1 );
	spinner5->set_alignment( GLUI_ALIGN_RIGHT );
	spinner6->set_int_limits( 0, 1 );
	spinner6->set_alignment( GLUI_ALIGN_RIGHT );	
	//new GLUI_Button( glui, "Delete last vertex", 5, control_cb);

	GLUI_Spinner *spinner7 =  new GLUI_Spinner( obj_panel, "Specular R:", &mat_specular[0]);
	GLUI_Spinner *spinner8 =  new GLUI_Spinner( obj_panel, "Specular G:", &mat_specular[1]);
	GLUI_Spinner *spinner9 =  new GLUI_Spinner( obj_panel, "Specualar B:", &mat_specular[2]);
	spinner7->set_int_limits( 0, 1 );
	spinner7->set_alignment( GLUI_ALIGN_RIGHT );
	spinner8->set_int_limits( 0, 1 );
	spinner8->set_alignment( GLUI_ALIGN_RIGHT );
	spinner9->set_int_limits( 0, 1 );
	spinner9->set_alignment( GLUI_ALIGN_RIGHT );

	GLUI_Spinner *spinner10 =  new GLUI_Spinner( obj_panel, "Emission R:", &mat_emission[0]);
	GLUI_Spinner *spinner11 =  new GLUI_Spinner( obj_panel, "Emission G:", &mat_emission[1]);
	GLUI_Spinner *spinner12 =  new GLUI_Spinner( obj_panel, "Emission B:", &mat_emission[2]);
	spinner10->set_int_limits( 0, 1 );
	spinner10->set_alignment( GLUI_ALIGN_RIGHT );
	spinner11->set_int_limits( 0, 1 );
	spinner11->set_alignment( GLUI_ALIGN_RIGHT );
	spinner12->set_int_limits( 0, 1 );
	spinner12->set_alignment( GLUI_ALIGN_RIGHT );

	GLUI_Spinner *spinner13 =  new GLUI_Spinner( obj_panel, "Shiny!:", &mat_shininess[0]);
	spinner13->set_int_limits( 0, 100 );
	spinner13->set_alignment( GLUI_ALIGN_RIGHT );
	///////////////////////////////////-----------table

	///////////////////////////////glass1
	obj_glass1 = new GLUI_Rollout(glui2, "Glass 1", false );
	GLUI_Spinner *g1spinner =  new GLUI_Spinner( obj_glass1, "Ambient R:", &mat_ambient_copa[0]);
	GLUI_Spinner *g1spinner2 =  new GLUI_Spinner( obj_glass1, "Ambient G:", &mat_ambient_copa[1]);
	GLUI_Spinner *g1spinner3 =  new GLUI_Spinner( obj_glass1, "Ambient B:", &mat_ambient_copa[2]);
	g1spinner->set_int_limits( 0, 1 );
	g1spinner->set_alignment( GLUI_ALIGN_RIGHT );
	g1spinner2->set_int_limits( 0, 1 );
	g1spinner2->set_alignment( GLUI_ALIGN_RIGHT );
	g1spinner3->set_int_limits( 0, 1 );
	g1spinner3->set_alignment( GLUI_ALIGN_RIGHT );

	GLUI_Spinner *g1spinner4 =  new GLUI_Spinner( obj_glass1, "Diffuse R:", &mat_diffuse_copa[0]);
	GLUI_Spinner *g1spinner5 =  new GLUI_Spinner( obj_glass1, "Diffuse G:", &mat_diffuse_copa[1]);
	GLUI_Spinner *g1spinner6 =  new GLUI_Spinner( obj_glass1, "Diffuse B:", &mat_diffuse_copa[2]);
	g1spinner4->set_int_limits( 0, 1 );
	g1spinner4->set_alignment( GLUI_ALIGN_RIGHT );
	g1spinner5->set_int_limits( 0, 1 );
	g1spinner5->set_alignment( GLUI_ALIGN_RIGHT );
	g1spinner6->set_int_limits( 0, 1 );
	g1spinner6->set_alignment( GLUI_ALIGN_RIGHT );	
	//new GLUI_Button( glui, "Delete last vertex", 5, control_cb);

	GLUI_Spinner *g1spinner7 =  new GLUI_Spinner( obj_glass1, "Specular R:", &mat_specular_copa[0]);
	GLUI_Spinner *g1spinner8 =  new GLUI_Spinner( obj_glass1, "Specular G:", &mat_specular_copa[1]);
	GLUI_Spinner *g1spinner9 =  new GLUI_Spinner( obj_glass1, "Specualar B:", &mat_specular_copa[2]);
	g1spinner7->set_int_limits( 0, 1 );
	g1spinner7->set_alignment( GLUI_ALIGN_RIGHT );
	g1spinner8->set_int_limits( 0, 1 );
	g1spinner8->set_alignment( GLUI_ALIGN_RIGHT );
	g1spinner9->set_int_limits( 0, 1 );
	g1spinner9->set_alignment( GLUI_ALIGN_RIGHT );

	GLUI_Spinner *g1spinner10 =  new GLUI_Spinner( obj_glass1, "Emission R:", &mat_emission_copa[0]);
	GLUI_Spinner *g1spinner11 =  new GLUI_Spinner( obj_glass1, "Emission G:", &mat_emission_copa[1]);
	GLUI_Spinner *g1spinner12 =  new GLUI_Spinner( obj_glass1, "Emission B:", &mat_emission_copa[2]);
	g1spinner10->set_int_limits( 0, 1 );
	g1spinner10->set_alignment( GLUI_ALIGN_RIGHT );
	g1spinner11->set_int_limits( 0, 1 );
	g1spinner11->set_alignment( GLUI_ALIGN_RIGHT );
	g1spinner12->set_int_limits( 0, 1 );
	g1spinner12->set_alignment( GLUI_ALIGN_RIGHT );

	GLUI_Spinner *g1spinner13 =  new GLUI_Spinner( obj_glass1, "Shiny!:", &mat_shininess_copa[0]);
	g1spinner13->set_int_limits( 0, 100 );
	g1spinner13->set_alignment( GLUI_ALIGN_RIGHT );
	////////////////////////////////-------glass1

	///////////////////////////////////glass 2
	obj_glass2 = new GLUI_Rollout(glui2, "Glass 2", false );
	GLUI_Spinner *g2spinner =  new GLUI_Spinner( obj_glass2, "Ambient R:", &mat_ambient_copa2[0]);
	GLUI_Spinner *g2spinner2 =  new GLUI_Spinner( obj_glass2, "Ambient G:", &mat_ambient_copa2[1]);
	GLUI_Spinner *g2spinner3 =  new GLUI_Spinner( obj_glass2, "Ambient B:", &mat_ambient_copa2[2]);
	g2spinner->set_int_limits( 0, 1 );
	g2spinner->set_alignment( GLUI_ALIGN_RIGHT );
	g2spinner2->set_int_limits( 0, 1 );
	g2spinner2->set_alignment( GLUI_ALIGN_RIGHT );
	g2spinner3->set_int_limits( 0, 1 );
	g2spinner3->set_alignment( GLUI_ALIGN_RIGHT );

	GLUI_Spinner *g2spinner4 =  new GLUI_Spinner( obj_glass2, "Diffuse R:", &mat_diffuse_copa2[0]);
	GLUI_Spinner *g2spinner5 =  new GLUI_Spinner( obj_glass2, "Diffuse G:", &mat_diffuse_copa2[1]);
	GLUI_Spinner *g2spinner6 =  new GLUI_Spinner( obj_glass2, "Diffuse B:", &mat_diffuse_copa2[2]);
	g2spinner4->set_int_limits( 0, 1 );
	g2spinner4->set_alignment( GLUI_ALIGN_RIGHT );
	g2spinner5->set_int_limits( 0, 1 );
	g2spinner5->set_alignment( GLUI_ALIGN_RIGHT );
	g2spinner6->set_int_limits( 0, 1 );
	g2spinner6->set_alignment( GLUI_ALIGN_RIGHT );	


	GLUI_Spinner *g2spinner7 =  new GLUI_Spinner( obj_glass2, "Specular R:", &mat_specular_copa2[0]);
	GLUI_Spinner *g2spinner8 =  new GLUI_Spinner( obj_glass2, "Specular G:", &mat_specular_copa2[1]);
	GLUI_Spinner *g2spinner9 =  new GLUI_Spinner( obj_glass2, "Specualar B:", &mat_specular_copa2[2]);
	g2spinner7->set_int_limits( 0, 1 );
	g2spinner7->set_alignment( GLUI_ALIGN_RIGHT );
	g2spinner8->set_int_limits( 0, 1 );
	g2spinner8->set_alignment( GLUI_ALIGN_RIGHT );
	g2spinner9->set_int_limits( 0, 1 );
	g2spinner9->set_alignment( GLUI_ALIGN_RIGHT );

	GLUI_Spinner *g2spinner10 =  new GLUI_Spinner( obj_glass2, "Emission R:", &mat_emission_copa2[0]);
	GLUI_Spinner *g2spinner11 =  new GLUI_Spinner( obj_glass2, "Emission G:", &mat_emission_copa2[1]);
	GLUI_Spinner *g2spinner12 =  new GLUI_Spinner( obj_glass2, "Emission B:", &mat_emission_copa2[2]);
	g2spinner10->set_int_limits( 0, 1 );
	g2spinner10->set_alignment( GLUI_ALIGN_RIGHT );
	g2spinner11->set_int_limits( 0, 1 );
	g2spinner11->set_alignment( GLUI_ALIGN_RIGHT );
	g2spinner12->set_int_limits( 0, 1 );
	g2spinner12->set_alignment( GLUI_ALIGN_RIGHT );

	GLUI_Spinner *g2spinner13 =  new GLUI_Spinner( obj_glass2, "Shiny!:", &mat_shininess_copa2[0]);
	g2spinner13->set_int_limits( 0, 100 );
	g2spinner13->set_alignment( GLUI_ALIGN_RIGHT );
	////////////////////////////////--------------glass2

	/////////////////////////////Bottle
	obj_bottle = new GLUI_Rollout(glui2, "Bottle", false );
	GLUI_Spinner *botspinner =  new GLUI_Spinner( obj_bottle, "Ambient R:", &mat_ambient_bot[0]);
	GLUI_Spinner *botspinner2 =  new GLUI_Spinner( obj_bottle, "Ambient G:", &mat_ambient_bot[1]);
	GLUI_Spinner *botspinner3 =  new GLUI_Spinner( obj_bottle, "Ambient B:", &mat_ambient_bot[2]);
	botspinner->set_int_limits( 0, 1 );
	botspinner->set_alignment( GLUI_ALIGN_RIGHT );
	botspinner2->set_int_limits( 0, 1 );
	botspinner2->set_alignment( GLUI_ALIGN_RIGHT );
	botspinner3->set_int_limits( 0, 1 );
	botspinner3->set_alignment( GLUI_ALIGN_RIGHT );

	GLUI_Spinner *botspinner4 =  new GLUI_Spinner( obj_bottle, "Diffuse R:", &mat_diffuse_bot[0]);
	GLUI_Spinner *botspinner5 =  new GLUI_Spinner( obj_bottle, "Diffuse G:", &mat_diffuse_bot[1]);
	GLUI_Spinner *botspinner6 =  new GLUI_Spinner( obj_bottle, "Diffuse B:", &mat_diffuse_bot[2]);
	botspinner4->set_int_limits( 0, 1 );
	botspinner4->set_alignment( GLUI_ALIGN_RIGHT );
	botspinner5->set_int_limits( 0, 1 );
	botspinner5->set_alignment( GLUI_ALIGN_RIGHT );
	botspinner6->set_int_limits( 0, 1 );
	botspinner6->set_alignment( GLUI_ALIGN_RIGHT );	


	GLUI_Spinner *botspinner7 =  new GLUI_Spinner( obj_bottle, "Specular R:", &mat_specular_bot[0]);
	GLUI_Spinner *botspinner8 =  new GLUI_Spinner( obj_bottle, "Specular G:", &mat_specular_bot[1]);
	GLUI_Spinner *botspinner9 =  new GLUI_Spinner( obj_bottle, "Specualar B:", &mat_specular_bot[2]);
	botspinner7->set_int_limits( 0, 1 );
	botspinner7->set_alignment( GLUI_ALIGN_RIGHT );
	botspinner8->set_int_limits( 0, 1 );
	botspinner8->set_alignment( GLUI_ALIGN_RIGHT );
	botspinner9->set_int_limits( 0, 1 );
	botspinner9->set_alignment( GLUI_ALIGN_RIGHT );

	GLUI_Spinner *botspinner10 =  new GLUI_Spinner( obj_bottle, "Emission R:", &mat_emission_bot[0]);
	GLUI_Spinner *botspinner11 =  new GLUI_Spinner( obj_bottle, "Emission G:", &mat_emission_bot[1]);
	GLUI_Spinner *botspinner12 =  new GLUI_Spinner( obj_bottle, "Emission B:", &mat_emission_bot[2]);
	botspinner10->set_int_limits( 0, 1 );
	botspinner10->set_alignment( GLUI_ALIGN_RIGHT );
	botspinner11->set_int_limits( 0, 1 );
	botspinner11->set_alignment( GLUI_ALIGN_RIGHT );
	botspinner12->set_int_limits( 0, 1 );
	botspinner12->set_alignment( GLUI_ALIGN_RIGHT );

	GLUI_Spinner *botspinner13 =  new GLUI_Spinner( obj_bottle, "Shiny!:", &mat_shininess_bot[0]);
	botspinner13->set_int_limits( 0, 100 );
	botspinner13->set_alignment( GLUI_ALIGN_RIGHT );
	//////////////////////////////////---------------bottle

	////////////////cake
	obj_cake = new GLUI_Rollout(glui2, "Cake", true );
	GLUI_Spinner *cakespinner =  new GLUI_Spinner( obj_cake, "Ambient R:", &mat_ambient_cake[0]);
	GLUI_Spinner *cakespinner2 =  new GLUI_Spinner( obj_cake, "Ambient G:", &mat_ambient_cake[1]);
	GLUI_Spinner *cakespinner3 =  new GLUI_Spinner( obj_cake, "Ambient B:", &mat_ambient_cake[2]);
	cakespinner->set_int_limits( 0, 1 );
	cakespinner->set_alignment( GLUI_ALIGN_RIGHT );
	cakespinner2->set_int_limits( 0, 1 );
	cakespinner2->set_alignment( GLUI_ALIGN_RIGHT );
	cakespinner3->set_int_limits( 0, 1 );
	cakespinner3->set_alignment( GLUI_ALIGN_RIGHT );

	GLUI_Spinner *cakespinner4 =  new GLUI_Spinner( obj_cake, "Diffuse R:", &mat_diffuse_cake[0]);
	GLUI_Spinner *cakespinner5 =  new GLUI_Spinner( obj_cake, "Diffuse G:", &mat_diffuse_cake[1]);
	GLUI_Spinner *cakespinner6 =  new GLUI_Spinner( obj_cake, "Diffuse B:", &mat_diffuse_cake[2]);
	cakespinner4->set_int_limits( 0, 1 );
	cakespinner4->set_alignment( GLUI_ALIGN_RIGHT );
	cakespinner5->set_int_limits( 0, 1 );
	cakespinner5->set_alignment( GLUI_ALIGN_RIGHT );
	cakespinner6->set_int_limits( 0, 1 );
	cakespinner6->set_alignment( GLUI_ALIGN_RIGHT );	


	GLUI_Spinner *cakespinner7 =  new GLUI_Spinner( obj_cake, "Specular R:", &mat_specular_cake[0]);
	GLUI_Spinner *cakespinner8 =  new GLUI_Spinner( obj_cake, "Specular G:", &mat_specular_cake[1]);
	GLUI_Spinner *cakespinner9 =  new GLUI_Spinner( obj_cake, "Specualar B:", &mat_specular_cake[2]);
	cakespinner7->set_int_limits( 0, 1 );
	cakespinner7->set_alignment( GLUI_ALIGN_RIGHT );
	cakespinner8->set_int_limits( 0, 1 );
	cakespinner8->set_alignment( GLUI_ALIGN_RIGHT );
	cakespinner9->set_int_limits( 0, 1 );
	cakespinner9->set_alignment( GLUI_ALIGN_RIGHT );

	GLUI_Spinner *cakespinner10 =  new GLUI_Spinner( obj_cake, "Emission R:", &mat_emission_cake[0]);
	GLUI_Spinner *cakespinner11 =  new GLUI_Spinner( obj_cake, "Emission G:", &mat_emission_cake[1]);
	GLUI_Spinner *cakespinner12 =  new GLUI_Spinner( obj_cake, "Emission B:", &mat_emission_cake[2]);
	cakespinner10->set_int_limits( 0, 1 );
	cakespinner10->set_alignment( GLUI_ALIGN_RIGHT );
	cakespinner11->set_int_limits( 0, 1 );
	cakespinner11->set_alignment( GLUI_ALIGN_RIGHT );
	cakespinner12->set_int_limits( 0, 1 );
	cakespinner12->set_alignment( GLUI_ALIGN_RIGHT );

	GLUI_Spinner *cakespinner13 =  new GLUI_Spinner( obj_cake, "Shiny!:", &mat_shininess_cake[0]);
	cakespinner13->set_int_limits( 0, 100 );
	cakespinner13->set_alignment( GLUI_ALIGN_RIGHT );
	/////////////////////----------cake

	//glui2->set_main_gfx_window(ventPrincipal);
	//glutPostRedisplay();

	GLUI_Master.set_glutIdleFunc( myGlutIdle );


	

	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

// Main loop
	glutMainLoop();

	return 0;
}

void BordeDerecha()
{
	//glColor3f(0.6,0.6,0.6);
	//glLineWidth(3.0f);
	//glBegin(GL_LINES);
	//glVertex2f(trajWidth/2,trajWidth);
	//glVertex2f(trajWidth/2,0);
	//glEnd();

	////borde arriba
	//glColor3f(0.6,0.6,0.6);
	//glLineWidth(6.0f);
	//glBegin(GL_LINES);
	//glVertex2f(-trajWidth/2,trajWidth);
	//glVertex2f(trajWidth/2,trajWidth);
	//glEnd();

	
} 

void draw_axes()
{
	glPushMatrix();
	glScalef(sca_x,sca_y,sca_z);

	glBegin( GL_LINES );

	glColor3f( 1.0, 0.0, 0.0 );
	glVertex3f( .8f, 0.05f, 0.0 );  glVertex3f( 1.0, 0.25f, 0.0 ); /* Letter X */
	glVertex3f( 0.8f, .25f, 0.0 );  glVertex3f( 1.0, 0.05f, 0.0 );
	glVertex3f( 0.0, 0.0, 0.0 );  glVertex3f( 1.0, 0.0, 0.0 ); /* X axis      */

	glColor3f( 0.0, 1.0, 0.0 );
	glVertex3f( 0.0, 0.0, 0.0 );  glVertex3f( 0.0, 1.0, 0.0 ); /* Y axis      */

	glColor3f( 0.0, 0.0, 1.0 );
	glVertex3f( 0.0, 0.0, 0.0 );  glVertex3f( 0.0, 0.0, 1.0 ); /* Z axis    */
	glEnd();

	glPopMatrix();

}

void DrawTable()
{
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); 
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); 
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); 
	glMaterialfv(GL_FRONT,GL_EMISSION, mat_emission);
	glMaterialfv(GL_FRONT,GL_AMBIENT, mat_ambient);

	glColor3f( 1.0, 0.0, 0.0 );

	glPushMatrix();
	
	glScalef(20,1,7);
	glTranslatef(0,-0.5,0);
	glutSolidCube(1);

	glPopMatrix();
}

void DrawCopa()
{
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse_copa); 
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular_copa); 
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess_copa); 
	glMaterialfv(GL_FRONT,GL_EMISSION, mat_emission_copa);
	glMaterialfv(GL_FRONT,GL_AMBIENT, mat_ambient_copa);

	glColor3f( 0.0, 0.7, 0.0 );

	glPushMatrix();
	glRotatef(270.0,1.0f,0.0f,0.0f);
	glTranslatef(2,1.3,0.2);
	
	gluCylinder(gluNewQuadric(),0.05f,0.05f,1.0f,32,32);
	glPopMatrix();

	glPushMatrix();
	glRotatef(-90.0,1.0f,0.0f,0.0f);
	glTranslatef(2,1.3,0);

	glutSolidCone(0.3,0.3,30,30);
	glPopMatrix();

	glPushMatrix();
	glRotatef(90.0,1.0f,0.0f,0.0f);
	glTranslatef(2,-1.3,-1.7);
	glutSolidCone(0.5,0.7,30,30);
	glPopMatrix();
}

void DrawCopa2()
{
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse_copa2); 
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular_copa2); 
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess_copa2); 
	glMaterialfv(GL_FRONT,GL_EMISSION, mat_emission_copa2);
	glMaterialfv(GL_FRONT,GL_AMBIENT, mat_ambient_copa2);

	//glColor3f( 0.0, 0.7, 0.0 );

	glPushMatrix();
	glRotatef(270.0,1.0f,0.0f,0.0f);
	glTranslatef(5,-0.5,0.2);
	
	gluCylinder(gluNewQuadric(),0.05f,0.05f,1.0f,32,32);
	glPopMatrix();

	glPushMatrix();
	glRotatef(-90.0,1.0f,0.0f,0.0f);
	glTranslatef(5,-0.5,0);

	glutSolidCone(0.3,0.3,30,30);
	glPopMatrix();

	glPushMatrix();
	glRotatef(90.0,1.0f,0.0f,0.0f);
	glTranslatef(5,0.5,-1.7);
	glutSolidCone(0.5,0.7,30,30);
	glPopMatrix();
}

void DrawBottle()
{
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse_bot); 
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular_bot); 
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess_bot); 
	glMaterialfv(GL_FRONT,GL_EMISSION, mat_emission_bot);
	glMaterialfv(GL_FRONT,GL_AMBIENT, mat_ambient_bot);

	//glColor3f( 0, 0.7, 1.0 );

	glPushMatrix();
	glTranslatef(5,0,-1.1);
	glRotatef(270.0,1.0f,0.0f,0.0f);
	gluCylinder(gluNewQuadric(),0.6f,0.6f,2.0f,32,32);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(5,2,-1.1);
	glRotatef(270.0,1.0f,0.0f,0.0f);
	glutSolidSphere(0.6,32,32);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(5,2.6,-1.1);
	glRotatef(270.0,1.0f,0.0f,0.0f);
	gluCylinder(gluNewQuadric(),0.2f,0.2f,0.5f,32,32);
	glPopMatrix();



}

void DrawCake()
{

	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse_cake); 
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular_cake); 
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess_cake); 
	glMaterialfv(GL_FRONT,GL_EMISSION, mat_emission_cake);
	glMaterialfv(GL_FRONT,GL_AMBIENT, mat_ambient_cake);

	
	glPushMatrix();
	glTranslatef(-6,0,2);
	glRotatef(270.0,1.0f,0.0f,0.0f);
	gluCylinder(gluNewQuadric(),1.2f,1.2f,1.2f,32,32);
	glPopMatrix();


	glPushMatrix();
	glTranslatef(-6,1.2,2);
	glRotatef(270.0,1.0f,0.0f,0.0f);
	gluDisk(gluNewQuadric(),0.00001,1.2f,32,32);
	glPopMatrix();

	/*glPushMatrix();
	glTranslatef(-6,0.6,2);
	glRotatef(270.0,1.0f,0.0f,0.0f);
	glutSolidTorus(1,1.3f,32,32);
	glPopMatrix();*/

	glPushMatrix();
	glTranslatef(-6,1.3,2);
	glutSolidSphere(0.2,10,10);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-6.8,1.2,2);
	glRotatef(270.0,1.0f,0.0f,0.0f);
	gluCylinder(gluNewQuadric(),0.02f,0.02f,0.4f,12,12);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-5.2,1.2,2);
	glRotatef(270.0,1.0f,0.0f,0.0f);
	gluCylinder(gluNewQuadric(),0.02f,0.02f,0.4f,12,12);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-6.4,1.2,2.6);
	glRotatef(270.0,1.0f,0.0f,0.0f);
	gluCylinder(gluNewQuadric(),0.02f,0.02f,0.4f,12,12);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-5.6,1.2,2.6);
	glRotatef(270.0,1.0f,0.0f,0.0f);
	gluCylinder(gluNewQuadric(),0.02f,0.02f,0.4f,12,12);
	glPopMatrix();

		glPushMatrix();
	glTranslatef(-6.4,1.2,1.4);
	glRotatef(270.0,1.0f,0.0f,0.0f);
	gluCylinder(gluNewQuadric(),0.02f,0.02f,0.4f,12,12);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(-5.6,1.2,1.4);
	glRotatef(270.0,1.0f,0.0f,0.0f);
	gluCylinder(gluNewQuadric(),0.02f,0.02f,0.4f,12,12);
	glPopMatrix();


	



}

void CentralDisplay()
{

	glutSetWindow(ventCentral);
	glClearColor(1, 0.7, 1,0.0);//cambiar a los background cuando tenga un sistema;
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);



	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	gluPerspective(60.0, 1.0, 0.1, 200.0);
	glMatrixMode( GL_MODELVIEW );

	setCamera(0,0,17,0,0,0); 

	glTranslatef(0,0,profundidad);
	glRotatef( rotation_y, 0.0, 0.5, 0.0 );
	glRotatef( rotation_x, 0.5, 0.0, 0.0 );
	
	DrawTable();
	DrawCopa();
	DrawCopa2();
	DrawBottle();
	DrawCake();
//	draw_axes();

	glPushMatrix();

	glTranslatef(obj_trans[0],obj_trans[1],obj_trans[2]);
	glScalef(sca_x,sca_y,sca_z);
	
	glPopMatrix();

	glFlush();

	

	glutSwapBuffers();

}

void CentralReshape(int w, int h)
{
		
}

void PrincipalReshape(int w, int h)
{
	
	glViewport(0,0,WindowSizeW,WindowSizeH);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(-1.0,1.0,-1.0,1.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();


	glutSetWindow(ventCentral);
	glutReshapeWindow(WindowSizeW,WindowSizeH);
	glutPositionWindow(0,0);

	glutSetWindow(ventPrincipal);
	glutReshapeWindow(TamRealVentanaW,TamRealVentanaH);

}

void PrincipalDisplay()
{
	glutSetWindow(ventPrincipal);
	glClearColor(1.0,0.0,0.5,0.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glFlush();
	glutSwapBuffers();
	

}



void setCamera(float posX, float posY, float posZ, float targetX, float targetY, float targetZ)
{
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(posX, posY, posZ, targetX, targetY, targetZ, 0, 1, 0); // eye(x,y,z), focal(x,y,z), up(x,y,z)
}







